package com.xuln.ipp.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Locale;

import javax.annotation.Resource;

import com.xuln.common.category.service.ICategoryService;
import com.xuln.framework.service.BaseService;
import com.xuln.ipp.dao.IArticleDao;
import com.xuln.ipp.entity.Article;
import com.xuln.ipp.service.IArticleService;

public class ArticleServiceImpl extends BaseService implements IArticleService {
	@Resource
	ICategoryService categoryService;
	@Resource
	IArticleDao articleDao;

	public void delete(Long articleId) {
		articleDao.deleteById(articleId);
	}

	public Article getArticle(long id, Locale locale) {
		return articleDao.getArticle(id, locale.toString());
	}

	public List<Article> getAllArticle(Locale locale) {
		return articleDao.getAllArticle(locale.toString());
	}

	public List<Article> getArticleByCatetoryId(long catetoryId, Locale locale) {
		return articleDao.getArticleByCatetoryId(catetoryId, locale.toString());
	}

	public void save(Article article) {
		Long id = articleDao.getKey() + 1;
		article.getPK().setId(id);
		articleDao.setNextKey(id);
		articleDao.save(article);
	}

	public void update(Article article) {
		article.setModifyDate(new Date());
		articleDao.update(article);
	}

}
